# -*- coding: utf-8 -*-
from datetime import timedelta

from jms.dwd.dwd_warhouse.dwd_wide_rank_basic_scaninfo_tms_incre_dt import jms_dwd__dwd_wide_rank_basic_scaninfo_tms_incre_dt
from jms.dwd.dwd_wide_abnormal_detail_waybill_dt import jms_dwd__dwd_wide_abnormal_detail_waybill_dt
from jms.dwd.oms.dwd_yl_oms_oms_waybill_incre_dt import jms_dwd__dwd_yl_oms_oms_waybill_incre_dt
from jms.dwd.oms.dwd_yl_oms_oms_order_incre_dt import jms_dwd__dwd_yl_oms_oms_order_incre_dt
from utils.operators.cluster_for_spark_sql_operator import SparkSqlOperator

jms_dwd__dwd_wide_summary_waybill_incre = SparkSqlOperator(
    task_id='jms_dwd__dwd_wide_summary_waybill_incre',
    task_concurrency=1,
    pool_slots=12,
    master='yarn',
    name='jms_dwd__dwd_wide_summary_waybill_incre_{{ execution_date | date_add(1) | cst_ds }}',
    sql='jms/dwd/dwd_warhouse/dwd_wide_summary_waybill_incre/execute.sql',
    driver_memory='20G',
    driver_cores=8,
    retries=1,
    email=['rongguangfan@jtexpress.com','yl_bigdata@yl-scm.com'],
    executor_cores=10,
    executor_memory='14G',
    num_executors=100,  # spark.dynamicAllocation.enabled 为 True 时，num_executors 表示最少 Executor 数
    conf={'spark.dynamicAllocation.enabled': 'true',  # 动态资源开启
          'spark.shuffle.service.enabled': 'true',  # 动态资源 Shuffle 服务开启
          #'spark.dynamicAllocation.maxExecutors': 100,  # 动态资源最大扩容 Executor 数
          'spark.dynamicAllocation.maxExecutors': 140,
          'spark.dynamicAllocation.cachedExecutorIdleTimeout': 180,  # 动态资源自动释放闲置 Executor 的超时时间(s)
          'spark.sql.sources.partitionOverwriteMode': 'dynamic',  # 允许删改已存在的分区
          'spark.executor.memoryOverhead': '6G',  # 堆外内存
          'spark.sql.shuffle.partitions': 5000,
          'spark.default.paralleism': 5000,
          'spark.hadoop.hive.exec.dynamic.partition.mode': 'true',
          'spark.shuffle.file.buffer': '64k',
          'spark.reducer.maxSizeInFlight': '96m',
          'spark.shuffle.io.maxRetries':'20',
          'spark.reducer.maxBlocksInFlightPerAddress':'3',
          #'spark.shuffle.compress':'true',
          'spark.shuffle.io.retryWait':'20',
          'spark.shuffle.memoryFraction': '0.8',
          'spark.shuffle.consolidateFiles': 'true',
          'spark.executor.extraJavaOptions': '-XX:+UseG1GC -XX:ParallelGCThreads=10',
          'spark.driver.extraJavaOptions': '-XX:+UseG1GC'
          #'spark.speculation':'true',
          #'spark.speculation.quantile':'0.75',
          #'spark.speculation.interval':'500ms',
          #'spark.speculation.multiplier':'2',
          # 'spark.sql.autoBroadcastJoinThreshold': 3221225472
    },
    yarn_queue='warehouse',
    execution_timeout=timedelta(minutes=60),
)

jms_dwd__dwd_wide_summary_waybill_incre << [
    jms_dwd__dwd_wide_rank_basic_scaninfo_tms_incre_dt
    ,jms_dwd__dwd_wide_abnormal_detail_waybill_dt
    ,jms_dwd__dwd_yl_oms_oms_waybill_incre_dt
    ,jms_dwd__dwd_yl_oms_oms_order_incre_dt
]